<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/12/19
 * Time: 14:34
 * 患者
 */
namespace Admin\Model;
    use Base\Model\BaseModel;
class PatientInfoModel extends BaseModel{
    protected $dbName = 'transplant_userinformation';
    protected $_validate = array(
        array('name', '', '用户名已经存在', self::VALUE_VALIDATE, 'unique', self::MODEL_BOTH),
        array('phone', 'require', '手机号必须填写', 1, '', 1),
        array('email', '', '邮箱已经存在', self::VALUE_VALIDATE, 'unique', self::MODEL_BOTH),
        array('phone','11','手机号长度不对！', self::VALUE_VALIDATE, 'length', self::MODEL_BOTH),
        array('phone','/^(0|86|17951)?(13[0-9]|15[012356789]|16[012356789]|17[012356789]|18[0-9]|14[57])[0-9]{8}$/','手机号不合法！',self::VALUE_VALIDATE),
        array('phone', '', '手机号已经存在', 0, 'unique', 3),
        array('email', 'email', '邮箱格式不正确！',0, '', 3),
        //array('idcard','checkIdCard', '身份证位数不正确',2),
        //array('idcard', '', '亲，每一个人的身份证是独一无二滴！',2),
    );
    protected $_auto = array(
        array('passwd','',2,'ignore'),//表示passwd字段编辑的时候留空则忽略。
        array('status', '1'),
        array('createTime','mydate','1','callback'),
        array('lastEditTime','mydate','3','callback'),
    );
       /**
    *简单的验证身份证
    */
   protected function checkIdCard($idcard){  
        if(empty($idcard)){  
            return false;  
        }  
            if(!preg_match('/^\d{17}(\d|x)$/i',$idcard) and !preg_match('/^\d{15}$/i',$idcard))
        {  
            return false;  
        }  
    }
    /**
    *自动添加时间函数
    */
    protected function mydate(){
        return date("Y-m-d H:i:s");
    }
    protected $_link=array(
        //省市
        'province' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'aerainfo',
            'foreign_key' => 'provenceid',
            'parent_key' => 'id',
            'mapping_fields' => 'aerainfo_id,aerainfo_name'
        ),
        //市县
        'city' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'aerainfo',
            'foreign_key' => 'cityid',
            'parent_key' => 'id',
            'mapping_fields' => 'aerainfo_id,aerainfo_name'
        ),
        //县区
        'region' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'aerainfo',
            'foreign_key' => 'regionid',
            'parent_key' => 'id',
            'mapping_fields' => 'aerainfo_id,aerainfo_name'
        ),
        //血型
        'blood' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'bloodtypeinfo',
            'foreign_key' => 'bloodid',
            'parent_key' => 'id',
//            'mapping_fields' => 'id,name'/
        ),
    );

}